128 Constant caesarKeyMax
128 Constant caesarMod

\ Generates a key for caesar
: KEY_CAESAR ( -- ) caesarKeyMax SET_KEYMAX GENERATE_KEY ;

\ Set our buffer to 1
: BUFFER_CAESAR ( -- ) 1 SET_BUFFER ;

\ Setup for caesar cipher
: SETUP_CAESAR ( -- ) BUFFER_CAESAR ;

\ Encrypt using our key
: ENCRYPT_CAESAR ( -- ) SETUP_CAESAR 
	READ_LINE
	0 EOF = IF
		
	ELSE
		BEGIN
			\ Fetch the char value, add the key to it, mod it by 128
			lineBuffer c@ GET_KEY + caesarMod MOD lineBuffer c!
			\ lineBuffer c@ .
			WRITE_LINE
			READ_LINE
			0 EOF =
		UNTIL
	ENDIF ;
	
\ Decrypt using our key
: DECRYPT_CAESAR ( -- ) SETUP_CAESAR 
	READ_LINE
	0 EOF = IF
		
	ELSE
		BEGIN
			\ Fetch the char value, add the key to it, mod it by 128
			lineBuffer c@ GET_KEY - caesarMod MOD lineBuffer c!
			WRITE_LINE
			READ_LINE
			0 EOF =
		UNTIL
	ENDIF ;